package org.mozhu.zufang.wechat.wx.model;

import lombok.Data;

import javax.xml.bind.annotation.*;
import java.util.List;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "xml")
@Data
public class Message {
    @XmlElement(name = "ToUserName")
    String to;
    @XmlElement(name = "FromUserName")
    String from;
    @XmlElement(name = "CreateTime")
    long createTime;
    /**
     * text, image, voice, video, location, link
     */
    @XmlElement(name = "MsgType")
    MessageType type;

    /**
     * for normal message
     */
    @XmlElement(name = "Content")
    String content;

    /**
     * for normal message
     */
    @XmlElement(name = "AgentID")
    String agentId;

    /**
     * for image message: picUrl & mediaId
     */
    @XmlElement(name = "PicUrl")
    String picUrl;
    @XmlElement(name = "MediaId")
    String mediaId;

    /**
     * for voice message: mediaId, format & recognition
     */
    @XmlElement(name = "Format")
    String format;
    @XmlElement(name = "Recognition")
    String recognition;

    /**
     * for video message: mediaId & thumbMediaId
     */
    @XmlElement(name = "ThumbMediaId")
    String thumbMediaId;

    /**
     * for location message: x, y, scale & label
     */
    @XmlElement(name = "Location_X")
    Double x;
    @XmlElement(name = "Location_Y")
    Double y;
    @XmlElement(name = "Scale")
    Integer scale;
    @XmlElement(name = "Label")
    String label;

    /**
     * for link message: mediaId & thumbMediaId
     */
    @XmlElement(name = "Title")
    String title;
    @XmlElement(name = "Description")
    String description;
    @XmlElement(name = "Url")
    String url;

    /**
     * for news message: articleCount & articles
     */
    @XmlElement(name = "ArticleCount")
    String articleCount;
    @XmlElementWrapper(name = "Articles")
    @XmlElement(name = "item")
    List<Article> articles;

    @XmlElement(name = "MsgId")
    String msgId;

    enum MessageType {
        text, image, voice, video, location, link, music, news
    }
}

